<?php
class Control_Data_calculateHistory {

	function calculateHistory() {
		
		$game 		= 	MooForm::request('game');
		
		$gameLangConf = MooConfig::get('game_lang.zh_en');
		if($gameLangConf[$game]) {
			$game = $gameLangConf[$game];
		}
		
		$date 	= 	MooForm::request('date');
		
		$daily_analyze = MooConfig::get('main.url.daily_analyze');
		
		$name = $game . "__" . $date;
		$url = $daily_analyze."?game=".$game."&date=".$date;
		
		$rs = MooUtil::curl_send($url);	
		$res = MooJson::decode($rs);
		
		
		$res = array($res);
		
		if($res) {
			$format = array("PayRate", "userRetention2", "userRetention3","userRetention7","userRetention14","userRetention30","deviceRetention2","deviceRetention3","deviceRetention7","deviceRetention14","deviceRetention30");
			foreach($res as $key => $val) {
				foreach ($val as $k => $v) {
					if($v >= 0 && $v < 1) {
						if (in_array($k, $format)) {
							$res[$key][$k] = ($v*100)."%";
						}
					}
				}
			}
		}	
		
		
		$type = MooForm::request('type');
		if($res && $type == "daochu") {
			$excelData = array();
			// 平台数据
			$dataDir = "calculateHistory";
			/**
			 * 导出数据的表头对应字段
			 */
			$keyValues = $this->OBJ->keyValuesConf;
			MooObj::get('Data')->exportExcel($name, $dataDir, $res, $keyValues);
		}
		
		
		
		$gameLangEnConf = MooConfig::get('game_lang.en_zh');
		if($gameLangEnConf[$game]) {
			$nowGame = $gameLangEnConf[$game];
		}
		
		MooView::set('nowGame', $nowGame);
		MooView::set('date', $date);
		
		MooView::set('data', $res);
		MooView::set('data2', $res);	
		MooView::set('data3', $res);
		MooView::set('data4', $res);
		
		MooView::render('dataHistoryView2');
	}
}